<?php
/************************FoxPHP威客系统************************/
/*                                                            */
/*  FoxPHP.Com (C)2006-2016 FoxPHP Inc.                       */
/*  This is NOT a freeware, use is subject to license terms   */
/*  FoxPHP威客系统是商业软件,使用于商业用途请购买授权         */
/*  V3.0 2016.3                                               */
/*  foxphp@aliyun.com                                         */
/*  http://www.foxphp.com                                     */
/*                                                            */
/**************************************************************/


namespace Member\Model;
use Think\Model;

class AuthGroupModel extends Model {
	
	public $usergroup;
	
	public function UserAllow($post){
		
		if(!$this->uid){
			$this->error='对不起，请登录后操作!';
			return false;
		}
		
		$member=M('Member')->token(false)->where(" uid=$this->uid ")->field('uid,usergroup')->find();
		
		if(empty($member['uid'])){
			$this->error='对不起，用户不存在!';
			return false;
		}
		
		$usergroup=intval($member['usergroup']);
		$this->usergroup=$this->token(false)->where(" id=$usergroup ")->find();
		
		
		foreach($post as $key=>$value){

			$function=$key.'Allow';
			if(!$this->$function($value)){
				return false;
			}
		}
		
		return true;

	}
	
	
	public function addserviceAllow($value=0){

		if(!$this->usergroup['addservice']){
			return true;
		}else{
			if($value >= $this->usergroup['addservice']){
				$this->error='对不起，您已发布'.$value.'个服务,普通服务商发布服务最大'.$this->usergroup['addservice'].'个';
				return false;
			}
			return true;	
		}
	}	
	
	public function addtaskAllow($value=''){

		if(!$this->usergroup['addtask']){
			return true;
		}else{

			$this->error='对不起，您所在的用户组不允许发布任务!';
			return false;
		}
	}
	
	public function checkserviceAllow($value=0){

		if($this->usergroup['checkservice']==1){
			return true;
		}else{
			return false;
		}
	}
	
	public function realnametaskAllow($value=''){
		
		   if(!$this->usergroup['realnametask']){

			    return $this->pass+=1;
				
		   }else{
			   
			      //if($this->IsSQL('member_info'," WHERE realname=1 AND uid='$this->uid'")){
					      
						  echo '<p>对不起,任务要求实名认证!</p><p>请您先进行实名认证.</p>';
					  
				  //}else{
					    
						  return true;
					  
				  //}
		   }

	}

	/*

	public function addnumbertaskAllow($value=''){
	      
		   
		   if(!$this->usergroup['addnumbertask']){
			   
			     return $this->pass+=1;
			   
		   }else{
	
				 $countarr=$this->MysqlFetchArray("SELECT COUNT(*) AS count,FROM_UNIXTIME(dateline,'%e') AS date FROM ".$this->GetTable('task')." WHERE uid='$this->uid' AND FROM_UNIXTIME(dateline,'%Y-%m-%d')=curdate() GROUP BY curdate()");		
				  
				 $count=empty($countarr[0]['count']) ? 0 : intval($countarr[0]['count']);
				  
				 if($count < $this->usergroup['addnumbertask']){
	  
	   
					  return $this->pass+=1;
					  
				 }else{
					 
					  $this->error='对不起，您每天发任务次数不能超过'.$this->usergroup['addnumbertask'].'次!';
				 }
		   }

	}
	
	*/
	
	public function maxmoneytaskAllow($value=''){

		   if($value > $this->usergroup['maxmoneytask']){

				  $this->error='对不起，任务赏金不能大于'.$this->usergroup['maxmoneytask'].'元!';
			   
				
		   }else{
			   
	             return $this->pass+=1;		    
		   }

	}
	
	
	public function smallmoneytaskAllow($value=''){
		
		
		   if($this->usergroup['smallmoneytask'] <= $value){

			    return $this->pass+=1;
				
		   }else{
			   
			    $this->error='对不起，任务赏金不能小于'.$this->usergroup['smallmoneytask'].'元!';
		   }

	}
	
	
	public function increasetaskAllow(){
		
		   if(!$this->usergroup['increasetask']){

			    return $this->pass+=1;
				
		   }else{
			   
			    $this->error='对不起，您所在的用户组没有权限加价!';
		   }
	}
	
	public function addmoneytaskAllow($money=0){
	       if($money < $this->usergroup['addmoneytask']){

			     $this->error='对不起，加价最小金额'.$this->usergroup['addmoneytask'].'元!';
				
		   }else{
			   
			     return $this->pass+=1;
			   
		   }
	}
	
	
	public function adddraftAllow(){
		
		   if($this->usergroup['adddraft']==1){

			    return $this->pass+=1;
				
		   }else{
			   
			    $this->error='对不起！您所在的用户组没有权限发布！';
		   }
	}
	
	
	public function joinmoneydraftAllow($value=0){
		
		  if($value <= $this->usergroup['joinmoneydraft'] ){

			    return $this->pass+=1;
				
		   }else{
			   
			    $this->error='对不起，你所在的用户组投稿赏金范围不能超过'.$this->usergroup['joinmoneydraft'].'元!';
		   }

	}
	
	public function uploadfilesdraftAllow(){
		
		   if(!$this->usergroup['uploadfilesdraft']){

			    return $this->pass+=1;
				
		   }else{
			   
			    $this->error='对不起，你所在的用户组投稿不能上传文件';
		   }

	}
	
	public function uploadfilestaskAllow(){
		
		   if(!$this->usergroup['uploadfilestask']){

			    return $this->pass+=1;
				
		   }else{
			   
			    $this->error='对不起，你所在的用户组发任务不能上传文件';
		   }

	}
	
	public function votedraftAllow(){
		
		   if(!$this->usergroup['votedraft']){

			    return $this->pass+=1;
				
		   }else{
			   
			    $this->error='对不起，你所在的用户组不能投票';
		   }

	}
	
	
	public function commentsdraftAllow(){
		
		   if(!$this->usergroup['commentsdraft']){

			    return $this->pass+=1;
				
		   }else{
			   
			    $this->error='对不起，你所在的用户组不能点评';
		   }

	}
		
	public function messagetaskAllow(){
		
		   if(!$this->usergroup['messagetask']){

			    return $this->pass+=1;
				
		   }else{
			   
			    $this->error='对不起，你所在的用户组不能留言';
		   }

	}
			
    public function appallowAllow(){
		
		   if(!$this->usergroup['appallow']){

			    return $this->pass+=1;
				
		   }else{
			   
			    $this->error='对不起，你所在的用户组不能使用该应用!';
		   }

	}	
	
	/*
	public function addnumberdraftAllow(){
		
		   if(!$this->usergroup['addnumberdraft']){
			   
			     return $this->pass+=1;
			   
		   }else{
		   
				 $countarr=$this->MysqlFetchArray("SELECT COUNT(*) AS count,FROM_UNIXTIME(dateline,'%e') AS date FROM ".$this->GetTable('task_draft')." WHERE uid='$this->uid' AND FROM_UNIXTIME(dateline,'%Y-%m-%d')=curdate() GROUP BY curdate()");		
				  
				 $count=empty($countarr[0]['count']) ? 0 : intval($countarr[0]['count']);
				  
				 if($count <= $this->usergroup['addnumberdraft']){
	  
	   
					  return $this->pass+=1;
					  
				 }else{
					 
					  $this->error='对不起，您每天投稿次数不能超过'.$this->usergroup['addnumberdraft'].'次!';
				 }
		   }
		
	}
	*/
		
}

?>